//#include <stdlib.h>
//#include <stdio.h>


typedef struct _link{
    struct _link *next;
    void *element;
} link;

link *lalloc()
{
    return (link *) malloc( sizeof(link) );
}

void AddElement( link *currentLink, void *newElem )
{
    if( currentLink->next == 0x0)
    {
        link *newLink = lalloc();
        newLink->next = 0x0;
        newLink->element = newElem;
        currentLink->next = newLink;
    }
    else AddElement( currentLink->next, newElem);
}

void RemoveElement(link *l, void *removeElem)
{
    if( l->next == 0x0){ printf("could not remove\n"); return; } // could not find element

    if( l->next->element ==  removeElem)
    {
        link *freeMe = l->next;
        printf("removing %p -> %p\n", freeMe, freeMe->element);
        l->next = freeMe->next;
        free( freeMe );
    }
    else RemoveElement( l->next, removeElem );
}

void printList(link *l)
{
    if( l != 0x0)
    {
        printf("%p.element = %i \n", l, *(int *)l->element );
        printList( l->next );
    }
}

void printList2( link *l )
{
    if( l != 0x0 ){
        printf("%i", *(int *) l->element );
        if( l->next != 0x0){
            printf(" - ");
            printList2( l->next );
        }else printf("\n");
    }
}

typedef struct _point2d2d {
    double x,y;
} point2d;

/*
void printListpoint2ds( link *l )
{
    if( l != 0x0 ){
        point2d p = *(point2d *) l->element;
        printf("(%.1f,%.1f)", p.x, p.y );
        if( l->next != 0x0){
            printf(" - ");
            printListpoint2ds( l->next );
        }else printf("\n");
    }
}
*/
